﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace NorthWin_Test.Dao
{
    public class UserDao:BaseDao
    {
        public DataTable GetAllUser()
        {
            SqlCommand command = new SqlCommand("select * from Users");
            command.CommandType = CommandType.Text;
            return GetData(command);
        }
        #region AddUser
        /// <summary>
        /// ham them mot User vao csdl
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public int AddUser(string userID, string userName)
        {
            Conn.Open();
            SqlCommand command = new SqlCommand("AddUser", Conn);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add("@userID", SqlDbType.Int).Value = userID;
            command.Parameters.Add("@userName", SqlDbType.NVarChar).Value = userName;
           

            int result = command.ExecuteNonQuery();


            Conn.Close();
            return result;

        }
        #endregion

        public int UpdateUser(string userID, string userName, string userIDKey)
        {
            Conn.Open();
            Conn.Open();
            SqlCommand command = new SqlCommand("UpdateUser", Conn);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add("@UserID", SqlDbType.Int).Value = userID;
            command.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = userName;
            command.Parameters.Add("@UserIDKey", SqlDbType.NVarChar).Value = userName;

            int result = command.ExecuteNonQuery();


            Conn.Close();
            return result;
        }

        public int DeleteUser(string userIDKey)
        {
            Conn.Open();
            Conn.Open();
            SqlCommand command = new SqlCommand("DeleteUser", Conn);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add("@UserIDKey", SqlDbType.NVarChar).Value = userIDKey;

            int result = command.ExecuteNonQuery();


            Conn.Close();
            return result;
        }

    }
}
